package com.lanou3g.code0420;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * Created by dllo on 18/4/20.
 */
public class ReadThread extends Thread {

    private Socket socket;

    public ReadThread(Socket socket) {
        this.socket = socket;
    }


    @Override
    public void run() {
        BufferedReader reader = null;
        PrintWriter pw = null;
        try {
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();
            reader = new BufferedReader(new InputStreamReader(is));
            pw = new PrintWriter(new OutputStreamWriter(os));
            String line = "";
            while ((line = reader.readLine()) != null){
                System.out.println(line);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (reader != null){
                try {
                    reader.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }


}
